
<script>
import { mapMutations } from "vuex";
export default {
  onLaunch: function () {
    // 全局只触发一次
    // 验证用户 不管在哪里
    let that = this;
    // if (process.env.NODE_ENV === "development") {
      // console.log = function(str){
      //   return "";
      // }
    // }
    uni.getStorage({
      key: "token",
      success(res) {
        that.$u.api.getUserInfo().then((res) => {
          if (res.user) {
            that.SET_MEMBER(res.user);
            // that.$store.dispatch('SET_MEMBER',res.user)
            uni.setStorage({
              key: "id",
              data: res.user.userId,
              fail() {
                console.log("fail::userid set in storage fail.");
              },
            });
          } else {
            that.$refs.tips.show({
              title: "认证过期,请重新登录",
              type: "default",
            });
            uni.removeStorage({
              key: "token",
              fail() {
                console.log("fail::userid remove fail.");
              },
            });
          }
        });
      },
      fail() {
        console.log("fail::token set in storage fail.");
      },
    });

    console.log("App Launch");
  },
  onShow: function () {
    // let token = null;
    // 获取token

    console.log("App Show");
  },
  onHide: function () {
    console.log("App Hide");
  },
  methods: {
    ...mapMutations(["SET_MEMBER"]),
  },
};
</script>

<style lang="scss">
@import "static/style/uview-ui/index.scss";
</style>

<style lang="scss">
/*每个页面公共css */
@import "~@/static/style/app.scss";
</style>
